package com.example.bgdharaniPlayer.model;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * 音频轨道模型类，包含音频文件的路径、名称、播放速度和重复次数
 */
public class AudioTrack implements Parcelable {
    private String id;
    private String path;
    private String title;
    private float playbackSpeed;
    private int repeatCount;
    private boolean isPlaying;

    public AudioTrack(String path, String title) {
        this.id = String.valueOf(System.currentTimeMillis());
        this.path = path;
        this.title = title;
        this.playbackSpeed = 1.0f;
        this.repeatCount = 1;
        this.isPlaying = false;
    }

    protected AudioTrack(Parcel in) {
        id = in.readString();
        path = in.readString();
        title = in.readString();
        playbackSpeed = in.readFloat();
        repeatCount = in.readInt();
        isPlaying = in.readByte() != 0;
    }

    public static final Creator<AudioTrack> CREATOR = new Creator<AudioTrack>() {
        @Override
        public AudioTrack createFromParcel(Parcel in) {
            return new AudioTrack(in);
        }

        @Override
        public AudioTrack[] newArray(int size) {
            return new AudioTrack[size];
        }
    };

    public String getId() {
        return id;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public float getPlaybackSpeed() {
        return playbackSpeed;
    }

    public void setPlaybackSpeed(float playbackSpeed) {
        this.playbackSpeed = playbackSpeed;
    }

    public int getRepeatCount() {
        return repeatCount;
    }

    public void setRepeatCount(int repeatCount) {
        this.repeatCount = repeatCount;
    }

    public boolean isPlaying() {
        return isPlaying;
    }

    public void setPlaying(boolean playing) {
        isPlaying = playing;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(id);
        dest.writeString(path);
        dest.writeString(title);
        dest.writeFloat(playbackSpeed);
        dest.writeInt(repeatCount);
        dest.writeByte((byte) (isPlaying ? 1 : 0));
    }
}